
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <dos.h>
#include <dir.h>
#include <time.h>
#include <stdarg.h>
#include <math.h>
#include <ctype.h>
#include <windows.h>

#define _COLD 1000  /*  col TRANSACT */
#define _CONSTI  -32767
#define _CONSTIP 32767
#define _CONSTR  -1.E38
#define _CONSTRP 1.E38
int _NS, _NU, _MPR, _ML ;
//int  _MT;
#define _name(x)      (*x).head.f1
#define _nomd(x)      (*x).head.f2
#define _prerd(x)     (*x).head.f3
#define _sprizn(x)    (*x).head.f4
#define _edzanpam(x)  (*x).head.f5
#define _tektime(x)   (*x).head.f6
#define _predd(x)     (*x).head.f7
#define _sledd(x)     (*x).head.f8
#define _prior(x)     (*x).head.f9
#define _adrmem(x)    (*x).head.f10
#define _adrjmpd(x)   (*x).head.f11
#define _nomproc(x)   (*x).head.f17
#define _itabpr(x)    (*x).head.f18
#define _pi(x)        (*x).head.f19
#define _pr(x)        (*x).head.f20

#define _otndu(x,n)   (*x).ustr[n].f12
#define _otndd(x,n)   (*x).ustr[n].f13
#define _fdu(x,n)     (*x).ustr[n].f14
#define _preddu(x,n)  (*x).ustr[n].f15
#define _sleddu(x,n)   (*x).ustr[n].f16



/* #define _otndu(x,n)   (*x).ustr[n].f12
#define _otndd(x,n)   (*x).ustr[n].f13
#define _fdu(x,n)     (*x).ustr[n].f14
#define _preddu(x,n)  (*x).ustr[n].f15
#define _sleddu(x,n)   (*x).ustr[n].f16    */

#define _sname(x)    (*x).f1
#define _nstore(x)   (*x).f2
#define _storev(x)   (*x).f3
#define  _stime(x)    (*x).f4
#define  _pam2(x)     (*x).f5
#define  _pam3(x)     (*x).f6
#define  _nob(x)      (*x).f7
#define  _smax(x)     (*x).f8
#define  _prmons(x)   (*x).f9
#define  _ocpam(x)    (*x).f10
#define  _fctname(x)  (*x).f1
#define  _nfct(x)     (*x).f2
#define  _ozf(x)      (*x).f3
#define  _apd(x)      (*x).f4
#define  _fctime(x)   (*x).f5
#define  _ust2(x)     (*x).f6
#define  _ust3(x)     (*x).f7
#define  _prmonf(x)   (*x).f8
#define  _imfp(x)     (*x).f9
#define  _ocust(x)   (*x).f10

#define _A  ;if(_preriv) return
void _newtranto();
void _voceredid();
void _sstop();
void _vibord();


void _RunTime();
void _release (struct fct_p *ust);
void _leave ( struct store_p *pm, unsigned long m);
void _vozobnoviti(struct pasp_d *d);
//void _voceredu(struct pasp_d *d1, struct pasp_d *d2, struct fct_p *u, unsigned f);
void _stat();
void _infFACILITY(double t);
void _infSTORE(double t);
void _infTABLE(int i);
void _stop();
void rezout(char * sstring);
FILE *_fg ,*_fe ;       /*  file Graf ,file Experiment data   */
FILE *frez;  /* file for simulation rezults */
char _filrez[4]; char _screnrez[4]; /* parametr rezults in file,on screen */
char _scrent[4]; /* parametr for time output onscreen */
long int _cold ;
long _t1 ,_t2 ;
struct tm *_ut1 ,*_ut2 ;
char *vid_mem, *solSysTime;///LL
char _ch=' ';
char stringout[120];
int l_x=1,l_y=1;
struct tabl_sol {char * tname;
            int a0;
            double a1;double a2;double a3;unsigned long a4;
            unsigned long a5; double a6; double a7; int a8;
            unsigned long * ut;double mint;double maxt; int frst;
            unsigned prmont:1;
	   } _mtab [_MT_1],_pt ; int _umt =0;

struct {char * prname;
        unsigned long mcold;
		 } _tabpr[_MPR_1];
       int _mpr =0;

struct {char * labname;
        unsigned long labcol; unsigned ord;
       } _tablab[_ML_1];  unsigned _ml =0;

struct _s1 {char * f1;
        unsigned long f2;
        unsigned f3;
        unsigned f4;
        unsigned long f5;
        double   f6;
        struct pasp_d * f7;
        struct pasp_d * f8;
        long int f9;
        struct store_p * f10;
        unsigned f11;
        int f17;
		  unsigned f18;
        long int *f19;
        double *f20;
       } ;

 struct _s2 {char f12;
		  char f13;
        long int f14;
        struct pasp_d * f15;
        struct pasp_d * f16;
		 };

struct pasp_d {struct _s1 head;
		 struct _s2 * ustr;
		 } * _freemem [_COLD],
						 * _pervd =NULL,  *_firstd,
                   * _posld =NULL,  *_lastd,
                   * _tekd ;
                  int _dlpd =sizeof(struct pasp_d),
							 _umf =-1;

struct store_p {
                  char  * f1;
                  unsigned f2;
                  unsigned f9;
                  unsigned long f3;
                  double    f4;
                  unsigned long f5;
                  double   f6;
                  unsigned f7;
		  unsigned long f8;
		  long int  f10;
		 } *_ps ,*_mps[_NS_1] ;
                 int _umps =0;
struct fct_p {
                char * f1;
                unsigned f2;
                unsigned f3;
                unsigned f8;
                double   f5;
                long int f6;
                double   f7;
	   	unsigned f9;
		unsigned long  f10;
                struct pasp_d *f4;

	       } *_fp ,* _mfp[_NU_1];
               int _umfp =0;
double _timed =0,_Modeltime =0;
long int _maxtr =0; int _preriv =0,
    _VarExp =1,_StopVar =1,_PriznCancel =0,_ukproc =0;

void _PrLineD ();
void _lab(int i);
void _label(int m);

struct store_p * _newstore ( char *name,unsigned long vol,unsigned n, unsigned m);

struct fct_p * _newfac (char *name,unsigned n,unsigned i,unsigned m);

void _newlab (char *c,unsigned ord);

void _monitorR (char *c,double a);

void _monitorI (char *c,long int a);
void _Initialisation ();
void _Prtime();
void _PrSimTime();
int _Chek(char *c,long int i,int _col, int up, char *a);
struct time *_st;
float _clock();
_notempty( struct store_p *a);
_full( struct store_p *a);
_busy( struct fct_p *a);
_notfull( struct store_p *a);
_notbusy( struct fct_p *a);
void _priority(long int a);
void _PRERD(unsigned pr,struct store_p *pm,unsigned long m);
 void _leave( struct store_p *pm,unsigned long m);
 void _storequeue(struct store_p *pm);
 long int _virstor( struct store_p *pm);
 struct pasp_d * _memoryalloc();
 void _cancel(int prm);
 	void transmemdel( struct pasp_d *p_s);
 double _randomm();
 long int _factorial(long int n);
 long int  _geometric(double m);
  double _normal(double m,double s);
   double _exponential(double m);
long int _poisson(double m);
long int _sluchvibor(long int a,long int b);
double _prex(  int arg0,double arg1,...);
double _maxi(int arg0,double arg1,...);
double _mini(int arg0,double arg1,...);
_probab(double x);
long int _fgetint(FILE *fe);
double _fgetreal(FILE *fe);
void _voceredid(struct pasp_d *dd);
void _sstop();
void _stat();
void _infFACILITY(double t);
void _infSTORE(double t);
void _infTABLE(int i);
void _RunTime();
void _statemodel();
  void rezout(char * sstring);
  void _facqueue(struct  fct_p * ust);
  void _voceredu(struct pasp_d *d1,struct pasp_d *d2,struct fct_p *u, long int f);
  void _newtab(char *n,int nt,double a,double h,double b,unsigned prmon);
void _waituntil(int x);
void _vibord();
float _ttime();
_empty( struct store_p *a);
 _digit( char c);
 void _enter( struct store_p *pm, unsigned long m);
 void _newtranto(int met,int pr,char *namepr,int colint,int colreal,int prm);
 void _readto( int met,int colint,int colreal,char * namepr,FILE *f);
 void _release(struct fct_p * ust);
 void _stop();
 void _tabulate(double x,struct tabl_sol * table);
 void _seize( struct  fct_p * ust, long int f);
 void _wait(double x);
  void w_write(FILE *f,int colint,int colreal);

